home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Rekt_ayMæk / Source / MyApp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  6.7 KB  |  264 lines

  1. #include "MyApp.h"
  2.  
  3. #include <LGrowZone.h>
  4. #include <UDrawingState.h>
  5. #include <UMemoryMgr.h>
  6. #include <UModalDialogs.h>
  7. #include <URegistrar.h>
  8. #include <UDebugging.h>
  9. #include <UEnvironment.h>
  10.  
  11. #include <LWindow.h>
  12. #include <LTabGroupView.h>
  13. #include <LEditText.h>
  14. #include <LCheckBox.h>
  15. #include <UAttachments.h>
  16.  
  17. #include <UControlRegistry.h>
  18.  
  19. #include <LThread.h>
  20. #include <UThread.h>
  21. #include <LCleanupTask.h>
  22.  
  23. #include "AppConstants.h"
  24.  
  25. #include "MyVUMeterPeriodical.h"
  26.  
  27.  
  28. // ---------------------------------------------------------------------------
  29. //    • main
  30. // ---------------------------------------------------------------------------
  31.  
  32. int main()
  33. {
  34.         // Set Debugging options
  35.     SetDebugThrow_(debugAction_Alert);
  36.     SetDebugSignal_(debugAction_Alert);
  37.  
  38.         // Initialize Memory Manager. Parameter is the number of
  39.         // master pointer blocks to allocate
  40.     InitializeHeap(15);
  41.     
  42.         // Initialize standard Toolbox managers
  43.     UQDGlobals::InitializeToolbox(&qd);
  44.  
  45.         // Check for Thread Manager.
  46.     if (UEnvironment::HasFeature(env_HasThreadManager) == false) {
  47.         ::StopAlert(ALRT_NoThreadManager, nil);
  48.         ::ExitToShell();
  49.     }
  50.  
  51.         // Install a GrowZone to catch low-memory situations    
  52.     new LGrowZone(20000);
  53.  
  54.         // Run the application.
  55.     new UMainThread;
  56.  
  57.     MyApp     theApp;
  58.     theApp.AddAttachment(new LYieldAttachment);
  59.     theApp.Run();
  60.  
  61.         // Make sure async tasks get cleaned up. This call is VERY IMPORTANT.
  62.         // (Note: LCleanupTask patches ExitToShell, so things get cleaned up
  63.         // appropriately if you kill the application.)
  64.     LCleanupTask::CleanUpAtExit();
  65.     
  66.     return 0;
  67. }
  68.  
  69.  
  70. // ---------------------------------------------------------------------------
  71. //    • MyApp                                    [public]
  72. // ---------------------------------------------------------------------------
  73. //    Applicaton object constructor
  74.  
  75. MyApp::MyApp()
  76. {
  77.         // Register ourselves with the Appearance Manager
  78.     if (UEnvironment::HasFeature(env_HasAppearance)) {
  79.         ::RegisterAppearanceClient();
  80.     }
  81.  
  82.     RegisterClasses();
  83.     
  84.         // Increase responsiveness for Networking
  85.     SetSleepTime(1);
  86. }
  87.  
  88.  
  89. // ---------------------------------------------------------------------------
  90. //    • ~MyApp                                [public, virtual]
  91. // ---------------------------------------------------------------------------
  92. //    Application object destructor
  93.  
  94. MyApp::~MyApp()
  95. {
  96.     // Nothing
  97. }
  98.  
  99.  
  100. // ---------------------------------------------------------------------------
  101. //    • StartUp                                        [protected, virtual]
  102. // ---------------------------------------------------------------------------
  103. //    Perform an action in response to the Open Application AppleEvent.
  104. //    Here, issue the New command to open a window.
  105.  
  106. void
  107. MyApp::StartUp()
  108. {
  109. //    ObeyCommand(cmd_New, nil);
  110.     ObeyCommand(cmd_About, nil);
  111.     ObeyCommand(1000, nil);
  112. }
  113.  
  114.  
  115. // ---------------------------------------------------------------------------
  116. //    • ObeyCommand                                    [public, virtual]
  117. // ---------------------------------------------------------------------------
  118. //    Respond to Commands. Returns true if the Command was handled, false if not.
  119.  
  120. Boolean
  121. MyApp::ObeyCommand(
  122.     CommandT    inCommand,
  123.     void*        ioParam)
  124. {
  125.     Boolean        cmdHandled = true;    // Assume we'll handle the command
  126.  
  127.     switch (inCommand) {
  128.  
  129.         case 1000:
  130.         {
  131.             MyVUMeterPeriodical::Instance().Toggle();
  132.             break;
  133.         }
  134.  
  135.         default: {
  136.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  137.             break;
  138.         }
  139.     }
  140.     
  141.     return cmdHandled;
  142. }
  143.  
  144.  
  145. // ---------------------------------------------------------------------------
  146. //    • FindCommandStatus                                [public, virtual]
  147. // ---------------------------------------------------------------------------
  148. //    Determine the status of a Command for the purposes of menu updating.
  149.  
  150. void
  151. MyApp::FindCommandStatus(
  152.     CommandT    inCommand,
  153.     Boolean&    outEnabled,
  154.     Boolean&    outUsesMark,
  155.     UInt16&        outMark,
  156.     Str255        outName)
  157. {
  158.     switch (inCommand) {
  159.  
  160.         case 1000:
  161.         {
  162.             outEnabled = true;
  163.             break;
  164.         }
  165.  
  166.         case cmd_Open: {
  167.             // The stationery default does nothing for these
  168.             // commands, so they are disabled to avoid any confusion
  169.             // in the menubar. If you implement the appropriate
  170.             // handler functions (e.g. ChooseDocument for cmd_Open)
  171.             // be certain to either remove the case from here
  172.             // (and let LDocApplication or another Commander handle it)
  173.             // or add your own handler here.
  174.             
  175.             outEnabled = false;
  176.             break;
  177.         }
  178.     
  179.         default: {
  180.             LDocApplication::FindCommandStatus(inCommand, outEnabled,
  181.                                             outUsesMark, outMark, outName);
  182.             break;
  183.         }
  184.     }
  185. }
  186.  
  187. // ---------------------------------------------------------------------------
  188. //    • MakeNewDocument                                [public, virtual]
  189. // ---------------------------------------------------------------------------
  190. //    What happens to File->New Session from the menu. Creates a settings dialog
  191. //    then waits modally for a configuration. If completed, then opens a new session.
  192.  
  193. LModelObject*
  194. MyApp::MakeNewDocument()
  195. {
  196.     return NULL;
  197. }
  198.  
  199.  
  200. // ---------------------------------------------------------------------------
  201. //    • OpenDocument                                        [public, virtual]
  202. // ---------------------------------------------------------------------------
  203. //    Open a Document specified by an FSSpec
  204.  
  205. void
  206. MyApp::OpenDocument(
  207.     FSSpec*        inMacFSSpec)
  208. {
  209. #pragma unused(inMacFSSpec)
  210.  
  211.     // You must implement.
  212. }
  213.  
  214.  
  215. // ---------------------------------------------------------------------------
  216. //    • PrintDocument                                        [public, virtual]
  217. // ---------------------------------------------------------------------------
  218. //    Print a Document specified by an FSSpec
  219.  
  220. void
  221. MyApp::PrintDocument(
  222.     FSSpec*        inMacFSSpec)
  223. {
  224. #pragma unused(inMacFSSpec)
  225.  
  226.     // You must implement
  227. }
  228.  
  229.  
  230. // ---------------------------------------------------------------------------
  231. //    • ChooseDocument                                    [public, virtual]
  232. // ---------------------------------------------------------------------------
  233. //    Allow the user to pick a Document (usually for opening)
  234.  
  235. void
  236. MyApp::ChooseDocument()
  237. {
  238.     // You must implement
  239. }
  240.  
  241.  
  242. // ---------------------------------------------------------------------------
  243. //    • RegisterClasses                                [protected, virtual]
  244. // ---------------------------------------------------------------------------
  245. //    To reduce clutter within the Application object's constructor, class
  246. //    registrations appear here in this seperate function for ease of use.
  247.  
  248. void
  249. MyApp::RegisterClasses()
  250. {
  251.         // Register core PowerPlant classes.
  252. //    RegisterClass_(LWindow);
  253.  
  254.         // Register the Appearance Manager/GA classes. You may want
  255.         // to remove this use of UControlRegistry and instead perform
  256.         // a "manual" registration of the classes. This cuts down on
  257.         // extra code being linked in and streamlines your app and
  258.         // project. However, use UControlRegistry as a reference/index
  259.         // for your work, and ensure to check UControlRegistry against
  260.         // your registrations each PowerPlant release in case
  261.         // any mappings might have changed.
  262.         
  263. //    UControlRegistry::RegisterClasses();
  264. }